#!/bin/bash

server_key=server.key
server_key_pass=111111
server_cert=server.crt
server_p12=server.p12
server_p12_pass=$server_key_pass
server_keystore=server.keystore
server_keystore_pass=111111

echo "convert $server_cert/$server_key to PKCS#12 format: $server_p12"
openssl pkcs12 -export -in $server_cert -inkey $server_key -passin pass:$server_key_pass -password pass:$server_p12_pass \
    -name server -out $server_p12

echo "convert $server_p12 to keystore: $server_keystore"
keytool -importkeystore -srckeystore $server_p12 -destkeystore $server_keystore \
    -srcstoretype pkcs12 -deststoretype jks -srcalias server -destalias server \
    -deststorepass $server_keystore_pass -srcstorepass $server_p12_pass